﻿using EntityModel;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class OrderAfterSalesController : ControllerBase
    {
        private readonly BitDbContext _db;

        public OrderAfterSalesController(BitDbContext db)
        {
            _db = db;
        }
        public Result Get()
        {

            Result result = new Result();
            result.Data = _db.EM_OrderAfterSales.ToList();
            return result;
        }


        #region 增
        [HttpPost]
        public Result Add([FromBody] EM_OrderAfterSales Sales)
        {
            Result result = new Result();
            _db.EM_OrderAfterSales.Add(Sales);
            result.Data = _db.SaveChanges();
            return result;
        }
        #endregion

        #region 删
        [HttpDelete]
        public Result Dele(Guid id)
        {
            Result result = new Result();
            EM_OrderAfterSales? Sales = _db.EM_OrderAfterSales.Where(w => w.OrderId == id).SingleOrDefault();
            if (Sales != null)
                _db.EM_OrderAfterSales.Remove(Sales);
            result.Data = _db.SaveChanges();
            return result;
        }
        [HttpPut("del")]
        public Result IsDel([FromHeader] Guid Id)
        {
            Result result = new Result();
            EM_OrderAfterSales? merchant = _db.EM_OrderAfterSales.Where(w => w.OrderId == Id).SingleOrDefault();
            
            result.Data = _db.SaveChanges();
            return result;

        }
        #endregion
    }
}
